<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title></title>
    <link rel="stylesheet" type="text/css" href="/tp/Public/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="/tp/Public/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="/tp/Public/css/style.css"/>
</head>

<body>
<div id="container">
    <!---->

    <nav id="header" class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#"><b>BBS</b></a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li id="tab_1">
                    <a href="<?php echo U('Article/index');?>"><b>首页</b></a>
                </li>
                <li id="tab_2">
                    <a href="<?php echo U('Sort/index');?>"><b>分类</b></a>
                </li>
                <li id="tab_3">
                    <a href="<?php echo U('User/index');?>"><b>会员</b></a>
                </li>
                <?php if($_SESSION['uid']!= null): ?><li id="tab_4">
                        <a href="<?php echo U('Article/add');?>"><b>发表</b></a>
                    </li><?php endif; ?>

            </ul>
            <form class="navbar-form navbar-left" role="search" action="<?php echo U('Index/search');?>" method="get">
                <div class="form-group">
                    <input type="text" class="form-control" name="keyword" placeholder="Search">
                </div>
            </form>
            <?php if($_SESSION['uid']== null): ?><ul class="nav navbar-nav navbar-right">
                    <li  id="tab_7">
                        <a href="<?php echo U('User/login');?>">
                            <b>登录</b>
                        </a>
                    </li>
                    <li id="tab_8">
                        <a href="<?php echo U('User/rigister');?>"><b>注册</b></a>
                    </li>
                </ul><?php endif; ?>
            <?php if($_SESSION['uid']!= null): ?><ul class="nav navbar-nav navbar-right">
                    <li id="tab_5">

                        <a href="<?php echo U('notice/index');?>">
                            <i class="icon-envelope"></i>
                            <span id="">1</span>
                        </a>
                    </li>
                    <li class="dropdown" id="tab_6">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <b><?php echo (session('uid')); ?></b>
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu" role="menu">
                            <li>
                                <a href="<?php echo U('User/info');?>"><b>个人网页</b></a>
                            </li>
                            <li>
                                <a href="<?php echo U('Home/User/set');?>"><b>设置</b></a>
                            </li>
                            <?php if($_SESSION['uid']== root): ?><li>
                                    <a href="<?php echo U('Home/Admin/index');?>"><b>后台管理</b></a>
                                </li><?php endif; ?>
                            <li class="divider"></li>
                            <li>
                                <a href="<?php echo U('User/logout');?>"><b>退出</b></a>
                            </li>
                        </ul>
                    </li>
                </ul><?php endif; ?>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container-fluid -->
</nav>

    <!---->

    <div id="main" class="container">
        <div class="row">
            <div class="col-md-8">
                <div class="panel panel-default">
                    <ol id="breadcrumb" class="panel-body breadcrumb">
                        <li>
                            <a href="<?php echo U('article/index');?>">首页</a>
                        </li>
                        <li>
                            <a href="<?php echo U('Sort/detail',array('id'=>$article['sort_id']));?>"><?php echo ($article['sort_name']); ?></a>
                        </li>
                    </ol>
                    <div class="panel-heading">
                        <h2 class="form-group article-title"><?php echo ($article['title']); ?></h2>
                        <h5>By <a href="<?php echo U('User/info',array('id'=>$article['author_id']));?>"><?php echo ($article['article_author']); ?></a>
                            <span><?php echo ($article['create_time']); ?></span></h5>
                    </div>
                    <div class="panel-heading">
                        <div class="panel">
                            <p>
                                <?php echo ($article['content']); ?>
                            </p>
                        </div>
                        <a href="#reply">
                            <button type="submit" class="btn btn-primary" for="reply">评论</button>
                        </a>
                        <!---->
                        <?php if(($_SESSION['uid']== $article['article_author'])or($visit_user_type == admin)): ?><button class="btn btn-primary" data-toggle="modal" data-target="#modal-article">编辑</button>
                            <!---->
                            <div class="modal fade" id="modal-article" tabindex="-1" role="dialog"
                                 aria-labelledby="myModalLabel" aria-hidden="true">
                                <div class="modal-dialog">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal"
                                                    aria-hidden="true"></button>
                                            <h4 class="modal-title" id="myModalLabel">
                                                编辑
                                            </h4>
                                        </div>
                                        <form action="<?php echo U('Article/edit');?>" method="post">

                                            <div class="modal-body">
                                                <div class="panel-body">
                                                    <input type="hidden" name="id" value="<?php echo ($article['id']); ?>"/>
                                                    <textarea class="form-control" name="content" rows="5" cols=""><?php echo ($article['content']); ?></textarea>
                                                </div>
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                                                </button>
                                                <button type="submit" class="btn btn-primary">提交更改</button>
                                            </div>
                                        </form>
                                    </div>
                                    <!-- /.modal-content -->
                                </div>
                                <!-- /.modal -->
                            </div>
                            <!---->
                            <!--<form style="display: inline" action="<?php echo U('Article/delete');?>" method="post">-->
                            <!--<input type="hidden" name="article_id" value="<?php echo ($article['id']); ?>"/>-->
                            <!--<button type="submit" class="btn btn-danger">删除</button>-->
                            <!--</form>-->

                            <button class="btn btn-danger" data-toggle="modal"
                                    data-target="#<?php echo ($article['delete_id']); ?>">删除
                            </button>
                            <!---->
                            <div class="modal fade" id="<?php echo ($article['delete_id']); ?>" tabindex="-1"
                                 role="dialog"
                                 aria-labelledby="$comment['from_id']}" aria-hidden="true">
                                <div class="modal-dialog modal-sm">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal"
                                                    aria-hidden="true"></button>
                                            <h4 class="modal-title danger" id="myModalLabel">
                                                确认删除？
                                            </h4>
                                        </div>
                                        <form style="display: inline" action="<?php echo U('Article/delete');?>"
                                              method="post">
                                            <div class="modal-body">
                                                <input type="hidden"
                                                       name="article_id"
                                                       value="<?php echo ($article['id']); ?>"/>
                                                <center>
                                                    <button type="submit" class="btn btn-danger">删除
                                                    </button>
                                                    <button type="button" class="btn btn-default"
                                                            data-dismiss="modal">取消
                                                    </button>
                                                </center>
                                            </div>
                                        </form>
                                    </div>
                                    <!-- /.modal-content -->
                                </div>
                                <!-- /.modal -->
                            </div>
                            <?php if($visit_user_type == 'admin' and $article['is_top'] == 0): ?><button name="setTop" type="submit" class="btn btn-success">置顶</button><?php endif; ?>
                            <?php if($visit_user_type == 'admin' and $article['is_top'] == 1): ?><button name="unsetTop" type="submit" class="btn btn-warning">取消置顶</button><?php endif; endif; ?>
                    </div>

                </div>
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><b>评论回复</b></h3>
                    </div>
                    <div class="panel-body">
                        <ul>
                            <?php if($comments == null): ?><li class="list-group-item">
                                    暂无回复
                                </li><?php endif; ?>
                            <?php if(is_array($comments)): foreach($comments as $key=>$comment): ?><li class="list-group-item">
                                    <a class="media-left" href="<?php echo U('User/info',array('id'=>$comment['from_id']));?>">
                                        <img src="/tp/Public/images/<?php echo ($comment['avatar_name']); ?>" alt="作者">
                                    </a>

                                    <div class="media-body">
                                        <p class="text-muted">
                                            <span><i class="icon-time icon"></i></span>
                                            <span><?php echo ($comment['create_time']); ?></span>
                                            <span><a href="<?php echo U('User/info',array('id'=>$comment['from_id']));?>"><?php echo ($comment['from_name']); ?></a></span>
                                        </p>

                                        <h3 class="media-heading topic-list-heading">
                                            <span><i class="icon-envelope-alt icon"></i></span>

                                            <?php if($comment['to_type'] != user): else: ?>
                                                <a href="<?php echo U('User/info',array('id'=>$comment['to_id']));?>">@<?php echo ($comment['to_name']); ?></a><?php endif; ?>
                                            <span><?php echo ($comment['content']); ?></span>
                                        </h3>

                                        <h3 class="media-heading topic-list-heading ">
                                            <button class="btn btn-primary" data-toggle="modal"
                                                    data-target="#<?php echo ($comment['reply_id']); ?>">回复
                                            </button>
                                            <!---->
                                            <div class="modal fade" id="<?php echo ($comment['reply_id']); ?>" tabindex="-1"
                                                 role="dialog"
                                                 aria-labelledby="$comment['from_id']}" aria-hidden="true">
                                                <div class="modal-dialog">
                                                    <div class="modal-content">
                                                        <div class="modal-header">
                                                            <button type="button" class="close" data-dismiss="modal"
                                                                    aria-hidden="true"></button>
                                                            <h4 class="modal-title" id="myModalLabel">
                                                                回复
                                                            </h4>
                                                        </div>
                                                        <form action="<?php echo U('Comment/add');?>" method="post">

                                                            <div class="modal-body">
                                                                <div class="panel-body">
                                                                    <input type="hidden" name="article_id"
                                                                           value="<?php echo ($comment['article_id']); ?>"/>
                                                                    <!-- name="from_id" 取决于session['uid']-->
                                                                    <input type="hidden" name="to_id"
                                                                           value="<?php echo ($comment['from_id']); ?>"/>
                                                                    <input type="hidden" name="to_type"
                                                                           value="user"/>
                                                                    <textarea class="form-control" name="content"
                                                                              rows="5" cols=""></textarea>
                                                                </div>
                                                            </div>
                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-default"
                                                                        data-dismiss="modal">关闭
                                                                </button>
                                                                <button type="submit" class="btn btn-primary">确定
                                                                </button>
                                                            </div>
                                                        </form>
                                                    </div>
                                                    <!-- /.modal-content -->
                                                </div>
                                                <!-- /.modal -->
                                            </div>

                                            <?php if(($_SESSION['uid']== $comment['from_name'])or($$visit_user_type == 'admin')): ?><input id="to_id" type="hidden" name="to_id"
                                                       value="<?php echo ($comment['from_id']); ?>"/>
                                                <input id="to_name" type="hidden" name="to_name"
                                                       value="<?php echo ($comment['from_name']); ?>"/>
                                                <button class="btn btn-primary" data-toggle="modal"
                                                        data-target="#<?php echo ($comment['id']); ?>">编辑
                                                </button>
                                                <!---->
                                                <div class="modal fade" id="<?php echo ($comment['id']); ?>" tabindex="-1"
                                                     role="dialog"
                                                     aria-labelledby="$comment['from_id']}" aria-hidden="true">
                                                    <div class="modal-dialog">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <button type="button" class="close" data-dismiss="modal"
                                                                        aria-hidden="true"></button>
                                                                <h4 class="modal-title" id="myModalLabel">
                                                                    编辑
                                                                </h4>
                                                            </div>
                                                            <form action="<?php echo U('Comment/edit');?>" method="post">

                                                                <div class="modal-body">
                                                                    <div class="panel-body">
                                                                        <input type="hidden" name="comment_id"
                                                                               value="<?php echo ($comment['id']); ?>"/>
                                                                    <textarea class="form-control"
                                                                              name="comment_content" rows="5" cols=""><?php echo ($comment['content']); ?></textarea>
                                                                    </div>
                                                                </div>
                                                                <div class="modal-footer">
                                                                    <button type="button" class="btn btn-default"
                                                                            data-dismiss="modal">关闭
                                                                    </button>
                                                                    <button type="submit" class="btn btn-primary">提交更改
                                                                    </button>
                                                                </div>
                                                            </form>
                                                        </div>
                                                        <!-- /.modal-content -->
                                                    </div>
                                                    <!-- /.modal -->
                                                </div>
                                                <!---->
                                                <button class="btn btn-danger" data-toggle="modal"
                                                        data-target="#<?php echo ($comment['delete_id']); ?>">删除
                                                </button>
                                                <!---->
                                                <div class="modal fade" id="<?php echo ($comment['delete_id']); ?>" tabindex="-1"
                                                     role="dialog"
                                                     aria-labelledby="$comment['from_id']}" aria-hidden="true">
                                                    <div class="modal-dialog modal-sm">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <button type="button" class="close" data-dismiss="modal"
                                                                        aria-hidden="true"></button>
                                                                <h4 class="modal-title danger" id="myModalLabel">
                                                                    确认删除？
                                                                </h4>
                                                            </div>
                                                            <form style="display: inline"
                                                                  action="<?php echo U('Comment/delete');?>"
                                                                  method="post">
                                                                <div class="modal-body">
                                                                    <input type="hidden" name="comment_id"
                                                                           value="<?php echo ($comment['id']); ?>"/>
                                                                    <center>
                                                                        <button type="submit" class="btn btn-danger">删除
                                                                        </button>
                                                                        <button type="button" class="btn btn-default"
                                                                                data-dismiss="modal">取消
                                                                        </button>
                                                                    </center>
                                                                </div>
                                                            </form>
                                                        </div>
                                                        <!-- /.modal-content -->
                                                    </div>
                                                    <!-- /.modal -->
                                                </div><?php endif; ?>
                                        </h3>
                                    </div>

                                </li><?php endforeach; endif; ?>
                        </ul>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <form action="<?php echo U('Comment/add');?>" method="post">
                            <textarea id="reply" class="form-control" name="content" rows="5" cols=""></textarea>
                            <input type="hidden" name="to_id" value="<?php echo ($sort['name']); ?>"/>
                            <br/>
                            <input type="hidden" name="article_id"
                                   value="<?php echo ($article ['id']); ?>"/>
                            <input type="hidden" name="to_id"
                                   value="<?php echo ($article['author_id']); ?>"/>
                            <input type="hidden" name="to_type"
                                   value="article"/>
                            <button type="submit" class="btn btn-default">评论</button>
                        </form>
                    </div>
                </div>

            </div>


        </div>

        <div class="col-md-4">


        </div>
    </div>

</div>

<!---->
</div>
<!---->

<footer id="footer">
    <div class="container">
        <p>Powered by BBS 2016-2017 Allright rights reserved</p>
    </div>
</footer>
<!---->
<script src="/tp/Public/js/jquery-1.11.0.js" type="text/javascript" charset="utf-8"></script>
<script src="/tp/Public/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/tp/Public/js/main.js" type="text/javascript" charset="utf-8"></script>
</body>

</html>